package com.share.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Test1Interceptor implements HandlerInterceptor {
    /*
    1、返回值：是否将当前的请求拦截下俩，如果返回false，请求将被终止
    2、参数Object：表示被拦截请求的目标
     */
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        System.out.println("####pre");
        System.out.println("####"+o.getClass().getSimpleName());//####HandlerMethod
        return true;
    }

    /*
   1、参数ModelAndView：可以通过该参数改变显示的视图，或修改发往视图的方法
    */
    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        System.out.println("####post");
        modelAndView.addObject("msg", "来自Test1Interceptor");
//        modelAndView.setViewName("xxx");
    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
        System.out.println("####after");
    }
}
